<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<% String contextPath = request.getContextPath(); 
    request.setAttribute("contextPath", contextPath);%>

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>人工充值</title>

    <!-- Bootstrap Core CSS -->
    <link href="${contextPath}/css/bootstrap.min.css" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="${contextPath}/css/metisMenu.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="${contextPath}/css/sb-admin-2.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="${contextPath}/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!--common Css-->
    <link href="${contextPath}/css/common.css" rel="stylesheet">
    <link href="${contextPath}/iconfont/iconfont.css" rel="stylesheet">

</head>

<body>

<div id="wrapper">

     <!-- Navigation -->
     <%@include file="nav.jsp"%>
    
	<div id="show"></div>
    <div id="page-wrapper">
    	<span id="show"></span>
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">人工充值</h3>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-lg-6" style="height: 300px; ">
 
                                    <div class="form-group">
                                        <label for="userId" class="col-sm-2 control-label">用户ID</label>
                                        <div class="col-lg-10">
                                            <input type="text" class="form-control" id="userId" name="userId" 

style="width: 200px; ">
                                        </div>
                                        <br/><br/>
                                    </div><div class="form-group">
                                        <label for="realname" class="col-sm-2 control-label">用户真实姓名</label>
                                        <div class="col-lg-10">
                                            <input type="text" class="form-control" id="realname" name="realname" 

readonly style="width: 200px; ">
                                        </div>
                                        <br/><br/>
                                    </div>
                                    
                                    <div class="form-group">
                                        <label for="num" class="col-sm-2 control-label">充钻金额</label>
                                        <div class="col-lg-10">
                                            <input type="text" class="form-control" id="num" name="num" 

style="width: 200px; ">
                                        </div><br/><br/>
                                    </div>
                                    <div class="form-group">
                                        <label for="money" class="col-sm-2 control-label">充钻数量</label>
                                        <div class="col-lg-10">
                                            <input type="text" class="form-control" id="money" name="money" 

readonly style="width: 200px; ">
                                        </div>
                                    </div><br/><br/><br/>
                                    <div class="form-group">
                                        <div class="col-md-6 col-md-offset-3" style="position:relative;left:-

130px">
                                            <button type="button" class="btn btn-default" id="sure">确认</button>
                                            <button type="button" class="btn btn-default" id="reset">取消</button>
                                        </div>
                                    </div>
                                
                            </div>
                        </div>
                    </div>
                    <!-- /.row (nested) -->
                </div>
                <!-- /.panel-body -->
            </div>
            <!-- /.panel -->
        </div>
    </div>
    <!-- /#page-wrapper -->

</div>



<!-- /#wrapper -->

<!-- jQuery -->
<script src="${contextPath}/js/jquery.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="${contextPath}/js/bootstrap.min.js"></script>

<!-- Metis Menu Plugin JavaScript -->
<script src="${contextPath}/js/metisMenu.min.js"></script>

<!-- Custom Theme JavaScript -->
<script src="${contextPath}/js/sb-admin-2.min.js"></script>

<!-- Page-Level Demo Scripts - Tables - Use for reference -->
<script>
 
 $(function(){
 		$("#reset").click(function(){
 		$("#userId").val("");
 		$("#realname").val("");
 		$("#num").val("");
 		$("#money").val("");
 	});
 		
 		
 
 
 	
 		 $("#num").mouseleave(function(){
 			
 			var transactionMoney=$("#num").val();
 			if(transactionMoney!=null&&transactionMoney!=''){
 			var json={
 				"transactionMoney":transactionMoney
 			};
 			$.ajax({
 				url:'${contextPath}/WebManager/callCenter/getRechargeScale',
 				type:'POST',
 				data:JSON.stringify(json),
 				dataType:'json',
 				contentType: "application/json;charset=utf-8", 
 				success:function(data){
 					if(data.message==='成功获取彩钻数量'){
 						$(".popupTip") .hide();
 						$("#money").val(data.data.accountFunds);
 					}
 					
 				}
 				
 			
 			
 			}) 
 			
 			}
 			
 		
 		});
 		 $("#userId").mouseleave(function(){
 			var userId=$("#userId").val();
 			if(userId!=null&&userId!=''){
 			var json={
 				"userId":userId
 			};
 			$.ajax({
 				url:'${contextPath}/WebManager/callCenter/getUserRealName',
 				type:'POST',
 				data:JSON.stringify(json),
 				dataType:'json',
 				contentType: "application/json;charset=utf-8", 
 				success:function(result){
 				   	if(result.message==="用户存在"){
 					if(result.data.realName!=null&&result.data.realName!=''){
 						$(".popupTip").hide();
 						 $("#realname").val(result.data.realName);
 					}else {
 						
 						if(result.data.userName!=null&&result.data.userName!=''){
 							$(".popupTip") .hide();
 							$("#realname").val(result.data.userName);
 						}else{
 							$(".popupTip") .hide();
 							$("#realname").val("用户未设置真实姓名和昵称");
 						}
 					}
 				}else {
 				$(".popupTip") .hide();
 				notice("没有此用户");
 				
 				}
 				
 			}
 				
 			
 			
 			}) 
 			
 			}
 			
 		
 		})
  
    	$("#sure").click(function(){
    		var userId = $("#userId").val();
    		var transactionMoney=$("#num").val();
    		var accountFunds = $("#money").val();
    		if(userId===''){
    			notice("请输入客户Id");
    			return false;
    		}else if(transactionMoney===''){
    			notice("请输入冲值金额");
    			return false;
    		}else if(accountFunds===''){
    			notice("稍等片刻,系统会自动为您计算冲钻数量");
    			return false;
    		}else{
    			$.ajax({
    			url:'${contextPath}/WebManager/callCenter/recharge',
				/* "{\"userId\":\""+userId+"\",\"num\":\""+num+"\",\"money\":\""+money+"\"}" */
				type:'POST',
				data:
				JSON.stringify({
				"userId":userId,
				"transactionMoney":transactionMoney,
				"accountFunds":accountFunds
				}),
				dataType:'json',
				contentType: "application/json;charset=utf-8", 
				success:function(data){
				
				if(data.message==="200"){
					$(".popupTip") .hide();
					   notice("充值成功");
					   $("#userId").val("");
 					   $("#realname").val("");
 		    		   $("#num").val("");
 					   $("#money").val("");
					    
					}else if(data.message==="400"){
						$(".popupTip") .hide();
						notice("充值出现异常失败了");
						
					}else if(data.message==="1"){
						$(".popupTip") .hide();
						notice("客服须登陆后才能为客户充值");
						setTimeout('jumpurl()',3000);
							
						
						
					
					}else if(data.message==="2"){
						$(".popupTip") .hide();
						notice("用户没有设置帐户");
						
					}
					
					
					
					var str = '';
					str += '<div class="alert alert-success" role="alert" id="success">';
					str += data.message;
					str += '</div>';
					$("#notice").html(str);
					/* window.location.href = '${contextPath}/callCenter/findPage'; */
				},
    		});
    		}
    	});
    	
    	$('[data-toggle="popover"]').popover();
		
        //提示信息封装函数
        function notice(notice) {
            var str = '';
            str += '<div class="popupTip" style="padding-right:20px">';
            str += notice;
            str += '<span class="iconfont icon-quxiao remove"></span>';
            str += '</div>';
            str += '</strong></div>';
            //wrapper插入str
            $("#wrapper").append(str);
        }

        //取消提示框
        $("#wrapper").on('click', '.remove', function(){
            $(".popupTip") .hide();
        });
    })
    function jumpurl(){  
  		location.href='${contextPath}/WebManager/callCenter/goToLogin';  
  	};
  	
  	 
	
	
	
</script>


</body>

</html>
